package com.xxjqr.rbac.exception;

import com.xxjqr.rbac.enums.CodeMsgEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class CommonException extends RuntimeException {

    // 序列化号
    private static final long serialVersionUID = 132719492019L;

    // 引入消息枚举
    private final CodeMsgEnum codeMsg;

    public CommonException(CodeMsgEnum codeMsg) {
        this.codeMsg = codeMsg;
    }

    public static CommonException generate(CodeMsgEnum msgEnum) {
        return new CommonException(msgEnum);
    }

    public static CommonException generate(String msg) {
        CodeMsgEnum notfound = CodeMsgEnum.NOTFOUND;
        notfound.setMsg(msg);
        return new CommonException(notfound);
    }
}

